package com.zr.service.driverclient.impl;


import com.zr.dao.base.BaseDriverDao;
import com.zr.service.driverclient.DriverService;
import com.zr.utils.Md5Util;
import com.zr.vo.base.BaseDriver;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class DriverServiceImpl implements DriverService {

    //司机Dao
    @Resource
    private BaseDriverDao baseDriverDao;

    /**
     * 司机端登录
     *
     * @param baseDriver
     * @return
     */
    @Override
    public BaseDriver login(BaseDriver baseDriver) {
        baseDriver.setPassword(Md5Util.md5(baseDriver.getPassword()));
        return baseDriverDao.login(baseDriver);
    }

    /**
     * 编辑司机信息
     *
     * @param baseDriver
     * @return
     */
    @Override
    public int edit(BaseDriver baseDriver) {
        if (baseDriver.getPassword() != null) {
            baseDriver.setPassword(Md5Util.md5(baseDriver.getPassword()));
        }
        baseDriver.setModifyTime(new Date());
        return baseDriverDao.updateByPrimaryKeySelective(baseDriver);
    }

    /**
     * 根据司机身份证查询司机信息
     *
     * @param driverId
     * @return
     */
    @Override
    public BaseDriver selectByDriverId(String driverId) {
        return baseDriverDao.selectByDriverId(driverId);
    }

}
